package main

import (
    "context"
    "golang.org/x/sys/windows"
    "net"
    "syscall"
)

var listenConfig = net.ListenConfig{
    Control:   MyControl,
}

func MyControl(network, address string, c syscall.RawConn) error {
    return c.Control(func(fd uintptr) {
        err := windows.SetsockoptInt(windows.Handle(fd), windows.SOL_SOCKET, windows.SO_REUSEADDR, 1)
        if err != nil {
            panic(err)
        }
    })
}

func main() {
    listener, err := listenConfig.Listen(context.Background(), "tcp", "127.0.0.1:8080")

    if err != nil {
        panic(err)
    }
    defer listener.Close()
    for {
        conn, err := listener.Accept()
        if err == nil {
            println("new connection ", conn.RemoteAddr().String())
        }
    }
}